<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2024/8/19
 * Time: 15:43
 */
namespace app\command;
use app\model\admin\Order;
use app\model\admin\OrderInfo;
use app\service\Keyword;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Db;

class SetKeyword extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('setkeyword')
            ->setDescription('the rundata command');
    }

    protected function execute(Input $input, Output $output)
    {
        try {
            $keywords = new Keyword();
            // 指令输出
            $keyword = Db::name('keyword')
                ->field('keyword')
                ->order('update_time ASC')
                ->limit(10)
                ->select()
                ->toArray();
            $keyword = array_column($keyword,'keyword');
            Order::where('create_time','<',date('Y-m-d H:i:s',time() - 3600))->delete();
            OrderInfo::where('create_time','<',date('Y-m-d H:i:s',time() - 3600))->delete();
            var_dump($keyword);
            echo date('Y-m-d H:i:s').'更新\n';
            foreach ($keyword AS $key => $value){
                echo $value.'完成更新数据\\n';
                $keywords->save($value);
                sleep(3);
            }
            die('ok');
        }catch (\Exception $e){
            dd($e->getTraceAsString());
            die;
        }
    }
}
